package top.suven.base.http.admin.order.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.order.model.Order;
import top.suven.base.http.admin.order.model.OrderUserFirstPayInfo;

import java.util.List;

/**
 * @Title: OrderWebDao.java
 * @Description: 订单的数据交互类
 * @author lixiangling
 * @date   2018/08/28 16:02:10
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface OrderWebDao extends CommonCrudMapper<Order> {
    @Select("<script> " +
    "select * from  rf_order where status='1' and enable_status='1' and order_id in " +
    "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
    "#{item} " +
    "</foreach> " +
    "</script>")
    @Results(
        id="order",
        value = {
            @Result(column = "order_id" , property = "orderId"),
			@Result(column = "pad_id" , property = "padId"),
			@Result(column = "pad_code" , property = "padCode"),
			@Result(column = "pad_grade" , property = "padGrade"),
			@Result(column = "goods_id" , property = "goodsId"),
			@Result(column = "user_id" , property = "userId"),
			@Result(column = "status" , property = "status"),
			@Result(column = "order_type" , property = "orderType"),
			@Result(column = "order_biz_type" , property = "orderBizType"),
			@Result(column = "order_price" , property = "orderPrice"),
			@Result(column = "real_fee" , property = "realFee"),
			@Result(column = "real_pay_amount" , property = "realPayAmount"),
			@Result(column = "favourable_fee" , property = "favourableFee"),
			@Result(column = "order_status" , property = "orderStatus"),
			@Result(column = "pay_mode_code" , property = "payModeCode"),
			@Result(column = "enable_status" , property = "enableStatus"),
			@Result(column = "online_time" , property = "onlineTime"),
			@Result(column = "finish_time" , property = "finishTime"),
			@Result(column = "creater" , property = "creater"),
			@Result(column = "create_time" , property = "createTime"),
			@Result(column = "modifier" , property = "modifier"),
			@Result(column = "modify_time" , property = "modifyTime"),
			@Result(column = "reorder" , property = "reorder"),
			@Result(column = "remark" , property = "remark"),
			@Result(column = "order_create_time" , property = "orderCreateTime"),
			@Result(column = "rbc_amount" , property = "rbcAmount"),
			@Result(column = "user_source" , property = "userSource"),
			@Result(column = "owner" , property = "owner"),
			@Result(column = "customer_ip" , property = "customerIp"),
			@Result(column = "goods_name" , property = "goodsName"),
			@Result(column = "auto_renew" , property = "autoRenew")
        }
    )
    List<Order> getSysRoleMenuByRoleCodeList(@Param("idList") List<String> idList);
    /**
     * @Title: 删除订单信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 16:02:10
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE rf_order set status='0'"+
            "WHERE order_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<String> idList);
    /**
     * @Title: 禁用订单信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 16:02:10
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
     @Update("<script> " +
             "UPDATE rf_order  " +
             "SET order_id = #{enableStatus}  " +
             "WHERE user_id IN " +
             "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
             "#{item} " +
             "</foreach> " +
             "</script>")
     void updateEnableStatus(@Param("enableStatus") String enableStatus, @Param("idList") List<String> idList);

	 @Select("<script> " +
			"select to_char(ORDER_CREATE_TIME, 'yyyy-MM-dd') as orderTime,count(distinct user_id) as count from rf_order "+
			"where status='1' and order_status in ('1','3','5','10','11') and ORDER_CREATE_TIME BETWEEN "+
			"to_timestamp(to_char(current_timestamp- interval '2 day', 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"and to_timestamp(to_char(current_timestamp, 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"group by to_char(ORDER_CREATE_TIME, 'yyyy-MM-dd') order by to_char(ORDER_CREATE_TIME, 'yyyy-MM-dd')"+
			"</script>")
	 List<OrderUserFirstPayInfo> getTwoDayPaidUserConversion();


}